package com.zdp.test.proxy.cglibproxy;

import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

/**
 * @describte:TODO
 * @program:ThoughtTest
 * @author:zhengdp
 * @create:2021-12-25 21:08:09
 **/
public class CglibProxyMehtodInvocation implements MethodInterceptor {

    // 被代理对象
    private Object target;

    public CglibProxyMehtodInvocation(Object target){
        this.target = target;
    }

    /**
     * @param o 代理对象
     * @param method 当前方法
     * @param objects 方法参数
     * @param methodProxy 通过该参数调用方法
     * @return
     * @throws Throwable
     */
    @Override
    public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
        System.out.println("Cglib Proxy 增强方法1");
        //methodProxy.invokeSuper(o,objects);
        methodProxy.invoke(target,objects);
        System.out.println("Cglib Proxy 增强方法2");
        return null;
    }
}
